package com.ningmengs789.live.ui.shopping.ui.fragment;

import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.ningmengs789.live.Interface.RequestCallback;
import com.ningmengs789.live.R;
import com.ningmengs789.live.http.JsonBuilder;
import com.ningmengs789.live.http.OKHttpUtils;
import com.ningmengs789.live.ui.fragment.BaseFragment;
import com.ningmengs789.live.ui.shopping.api.ShoppingApi;
import com.ningmengs789.live.utils.UserInfoUtil;

import org.json.JSONException;

import butterknife.BindView;

/**
 * 作者 : Administrator (yzhg)
 * 时间 : 2021-09-08 12:23
 * 包名 : com.ningmengs789.live.ui.shopping.ui.fragment
 * 备注：商品列表页面
 */
public class GoodsListFragment extends BaseFragment {


    public static String BUNDLE_GOODS_ID = "";

    public static GoodsListFragment newIntent(int goodId) {
        Bundle bundle = new Bundle();
        bundle.putInt(BUNDLE_GOODS_ID, goodId);
        GoodsListFragment goodsListFragment = new GoodsListFragment();
        goodsListFragment.setArguments(bundle);
        return goodsListFragment;
    }

    @Override
    protected int setContentViewById() {
        return R.layout.fragment_list_goods;
    }

    /**
     * 商品ID
     */
    private int goodsId = 0;

    /**
     * 商品ID展示
     */
    @BindView(R.id.tv_goods_id)
    TextView tvGoodsId;


    @Override
    protected void initAction() {
        Bundle bundle = getArguments();
        goodsId = bundle.getInt(BUNDLE_GOODS_ID, 0);

        tvGoodsId.setText(goodsId + "");
    }

    @Override
    protected void initData() {
        String body = "";
        try {
            body = new JsonBuilder()
                    .put("id", "-3")
                    .put("page", "1")
                    .put("types", "normal")
                    .put("name", "")
                    .build();
        } catch (Exception e) {
            e.printStackTrace();
        }

        OKHttpUtils.getInstance().getRequest(ShoppingApi.SHOPPING_FRAGMENT_LIST, body, new RequestCallback() {
            @Override
            public void onError(int errCode, String errInfo) {

            }

            @Override
            public void onSuccess(String result) {
                Log.i("获取到商品列表", "onSuccess: " + result);
            }
        });
    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected void updateViews(boolean isRefresh) {

    }
}
